<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
   

</body>

</html>
<script>
  

        //1.创建一个xhr对象
        var xhr = new XMLHttpRequest();

        console.log(xhr.readyState);
        //2.配置xhr对象
        //参数一：method  请求方式，get / post / delete / put
        //参数二：url 请求地址(资源路径)
        xhr.open('get', './data.json')

        console.log(xhr.readyState);
        //3.设置回调函数，用来接收返回的响应数据  

        xhr.onreadystatechange = function () {
            // console.log(xhr.readyState);
            if (xhr.readyState == 4) {
                document.write(JSON.parse(xhr.responseText));
            }

        }

        //4.发送请求
        xhr.send()
   

</script>